<?php
require_once("./session.php");
require_once("../include/global.php");


if(empty($_GET['action']))
{
print <<<HTML
<div id="articlelist" style="width:100%; margin:0 auto;padding-bottom:15px;">
  <div class="admin_title" >日志管理&nbsp;&nbsp;&nbsp;&nbsp;选择栏目
  <select name="category" onchange="window.location.href='$phpself?do=articles&cate_ID='+category.value;">
    <option value=''>所有栏目</option>
HTML;

$sql = "SELECT * FROM blog_category";
$result = mysql_query($sql) or die(mysql_error());
while($rs = mysql_fetch_object($result))
{
    print "<option value='$rs->cate_ID'>$rs->cate_Name</option>\n";
}

print <<<HTML
  </select>
  </div>
  <div id="content" style="width:100%; margin-top:10px;">
<table width="740" border="1" cellpadding="0" cellspacing="0" bordercolor="#ffffff">
<form name="articles" method="post">
  <tr style="background:#6784A4">
    <td width="22" align="center">
	<input name="selectall" type="checkbox" id="selectall" onclick="CheckAllBoxes('articles');" />
	</td>
    <td width="40" height="25" align="center">ID</td>
    <td width="300" align="center">日志标题</td>
    <td width="150" align="center">发表时间</td>
	<td width="100" align="center">所属栏目</td>
    <td colspan="2" align="center">操作</td>
    </tr>
HTML;

if(!empty($_GET['cate_ID']) && is_numeric($_GET['cate_ID']))
{$sql = "SELECT * FROM blog_article where log_CateID=".$_GET['cate_ID']." order by log_PostTime desc";}
else{$sql = "SELECT * FROM blog_article order by log_PostTime desc";}
$result = mysql_query($sql) or die(mysql_error());
while($rs = mysql_fetch_object($result))
{
     $time = strftime("%B %d,%Y,%H:%M %p",$rs->log_PostTime);
print <<<HTML
  <tr>
    <td align="center">
	<input name="select1" type="checkbox" id="select" name="select" />
	</td>
    <td height="20" align="center">$rs->log_ID</td>
    <td align="center">$rs->log_Title</td>
    <td align="center">$time</td>
	<td align="center">$rs->log_CateID</td>
    <td width="30" align="center">
	<a href="$phpself?do=write&action=modify&logID=$rs->log_ID" ><img src="./images/icon_edit.gif" alt="编辑" width="16" height="16" /></a></td>
    <td width="30" align="center">
	<a href="$phpself?do=articles&action=delete&log_ID=$rs->log_ID" ><img src="./images/icon_del.gif" alt="删除" width="16" height="16" /></a></td>
  </tr>
HTML;
}
  
print <<<HTML
</form>
</table>
    <p><button name="delete">删除所选日志</button></p>
  </div>
</div>
HTML;
}
else
{
    switch($_GET['action'])
	{
	    case "delete" :
		   if(!empty($_GET['log_ID']) && is_numeric($_GET['log_ID']))
		   {  
		      DelArticle($_GET['log_ID']);
				echo "<script>location.href='main.php?do=articles';</script>"; 
		   }
		   break;
		   
		default:break;
	}
}
?>
